using System;
using System.Data;
using System.Collections.Generic;
using ADOBase;
namespace eTMS.DAO{
	/********************************BEGIN KhoaDAO****************************************/
	///<summary>
	/// <para>Author: Auto generated class by CSharp Code Generator v2.0</para>
	/// <para>Date:26/10/2011 34:05:09</para>
	/// <para>Class Name: KhoaDAO</para>
	/// <para>Description: Class access to table Khoa in database. Coder should'nt code here.</para>
	///</summary>

	
	public partial class KhoaDAO : DAOBase<KhoaEntity>{


		#region Select functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateSelectOneCommand</para>
		/// <para>Input: Khoa_ID</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectOneCommand(int Khoa_ID){
			string strSQL="SELECT  [Khoa_ID],[MaKhoa],[TenKhoa],[MoTaKhoa] FROM [Khoa]  WHERE [Khoa].[Khoa_ID]=@Khoa_ID";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@Khoa_ID",Khoa_ID);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: SelectOne</para>
		/// <para>Input: Khoa_ID</para>
		/// <para>Output: KhoaEntity</para>
		///</summary>
		public KhoaEntity SelectOne(int Khoa_ID){
			IDbCommand cmd=this.CreateSelectOneCommand(Khoa_ID);
			return this.Select(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: SelectOneByMaKhoa</para>
		/// <para>Input: MaKhoa</para>
		/// <para>Output: KhoaEntity</para>
		///</summary>
		public KhoaEntity SelectOneByMaKhoa(string MaKhoa){
			IDbCommand cmd=this.CreateSelectAllByKeyCommand("MaKhoa",MaKhoa);
			return this.Select(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateSelectAllCommand</para>
		/// <para>Input: </para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectAllCommand(){
			string strSQL="SELECT  [Khoa_ID],[MaKhoa],[TenKhoa],[MoTaKhoa] FROM [Khoa] ";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateSelectAllByKeyCommand</para>
		/// <para>Input: ColumnName,ColumnValue</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectAllByKeyCommand(string ColumnName,object Value){
			string strSQL="SELECT  [Khoa_ID],[MaKhoa],[TenKhoa],[MoTaKhoa] FROM [Khoa]  WHERE [Khoa].["+ColumnName+"]=@ColumnName";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@ColumnName",Value);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: SelectAll</para>
		/// <para>Input: </para>
		/// <para>Output: List of KhoaEntity</para>
		///</summary>
		public List<KhoaEntity> SelectAll(){
			IDbCommand cmd=this.CreateSelectAllCommand();
			return this.SelectList(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: SelectAllDS</para>
		/// <para>Input: </para>
		/// <para>Output: DataSet</para>
		///</summary>
		public DataSet SelectAllDS(){
			IDbCommand cmd=this.CreateSelectAllCommand();
			return this.SelectDS(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateSelectAllFilterCommand</para>
		/// <para>Input: </para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectAllFilterCommand(string strFilter){
			string strSQL="SELECT  [Khoa_ID],[MaKhoa],[TenKhoa],[MoTaKhoa] FROM [Khoa]  WHERE "+RemoveInjection(strFilter);
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateSelectAllByKeyFilterCommand</para>
		/// <para>Input: ColumnName,ColumnValue</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectAllByKeyFilterCommand(string strFilter,string ColumnName,object Value){
			string strSQL="SELECT  [Khoa_ID],[MaKhoa],[TenKhoa],[MoTaKhoa] FROM [Khoa]  WHERE [Khoa].["+ColumnName+"]=@ColumnName AND "+RemoveInjection(strFilter);
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@ColumnName",Value);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: SelectAll</para>
		/// <para>Input: </para>
		/// <para>Output: List of KhoaEntity</para>
		///</summary>
		public List<KhoaEntity> SelectAllFilter(string strFilter){
			IDbCommand cmd=this.CreateSelectAllFilterCommand(strFilter);
			return this.SelectList(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: SelectAllDSFilter</para>
		/// <para>Input: </para>
		/// <para>Output: DataSet</para>
		///</summary>
		public DataSet SelectAllDSFilter(string strFilter){
			IDbCommand cmd=this.CreateSelectAllFilterCommand(strFilter);
			return this.SelectDS(cmd);
		}
		#endregion

		#region Insert functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateInsertCommand</para>
		/// <para>Input: KhoaEntity</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateInsertCommand(KhoaEntity o){
			string strSQL="INSERT INTO [Khoa]([MaKhoa],[TenKhoa],[MoTaKhoa]) VALUES  (@MaKhoa,@TenKhoa,@MoTaKhoa);SELECT  @@IDENTITY";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			if(o.IsNullMaKhoa)
				this.CreateCommandParameter(cmd,"@MaKhoa",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@MaKhoa",o.MaKhoa);

			if(o.IsNullTenKhoa)
				this.CreateCommandParameter(cmd,"@TenKhoa",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@TenKhoa",o.TenKhoa);

			if(o.IsNullMoTaKhoa)
				this.CreateCommandParameter(cmd,"@MoTaKhoa",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@MoTaKhoa",o.MoTaKhoa);


			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: Save</para>
		/// <para>Input: KhoaEntity</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool Save(KhoaEntity o){
			bool result=false;
			IDbCommand cmd=this.CreateInsertCommand(o);
			object id=this.ExecuteScalar(cmd,ref result);
			cmd.Dispose();
			try{
				o.Khoa_ID=int.Parse(Convert.ToString(id));
			}
			catch{}
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: SaveList</para>
		/// <para>Input: List of KhoaEntity</para>
		/// <para>Output: </para>
		///</summary>
		public void SaveList(List<KhoaEntity>list){
			foreach(KhoaEntity o in list){
				try{
					this.Save(o);
				}
				catch{
				}
			}
		}
		#endregion

		#region Update functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateUpdateCommand</para>
		/// <para>Input: KhoaEntity</para>
		/// <para>Output: </para>
		///</summary>
		protected IDbCommand CreateUpdateCommand(KhoaEntity o){
			string strSQL="UPDATE  [Khoa] SET [Khoa].[MaKhoa]=@MaKhoa,[Khoa].[TenKhoa]=@TenKhoa,[Khoa].[MoTaKhoa]=@MoTaKhoa WHERE [Khoa].[Khoa_ID]=@Khoa_ID";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			if(o.IsNullKhoa_ID)
				this.CreateCommandParameter(cmd,"@Khoa_ID",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@Khoa_ID",o.Khoa_ID);

			if(o.IsNullMaKhoa)
				this.CreateCommandParameter(cmd,"@MaKhoa",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@MaKhoa",o.MaKhoa);

			if(o.IsNullTenKhoa)
				this.CreateCommandParameter(cmd,"@TenKhoa",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@TenKhoa",o.TenKhoa);

			if(o.IsNullMoTaKhoa)
				this.CreateCommandParameter(cmd,"@MoTaKhoa",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@MoTaKhoa",o.MoTaKhoa);


			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateUpdateFieldCommand</para>
		/// <para>Input: ColumnName,ColumnValue,Khoa_ID</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateUpdateFieldCommand(string ColumnName,object Value,int Khoa_ID){
			string strSQL="UPDATE  [Khoa] SET [Khoa].["+ColumnName+"]=@ColumnName WHERE [Khoa].[Khoa_ID]=@Khoa_ID";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@Khoa_ID",Khoa_ID);



			this.CreateCommandParameter(cmd,"@ColumnName",Value);


			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: Update</para>
		/// <para>Input: KhoaEntity</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool Update(KhoaEntity o){
			IDbCommand cmd=this.CreateUpdateCommand(o);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: UpdateList</para>
		/// <para>Input: List of KhoaEntity</para>
		/// <para>Output: </para>
		///</summary>
		public void UpdateList(List<KhoaEntity>list){
			foreach(KhoaEntity o in list){
				try{
					this.Update(o);
				}
				catch{
				}
			}
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: UpdateMaKhoa</para>
		/// <para>Input: NewMaKhoa,Khoa_ID</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool UpdateMaKhoa(string NewMaKhoa,int Khoa_ID){
			IDbCommand cmd=this.CreateUpdateFieldCommand("MaKhoa",NewMaKhoa,Khoa_ID);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: UpdateTenKhoa</para>
		/// <para>Input: NewTenKhoa,Khoa_ID</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool UpdateTenKhoa(string NewTenKhoa,int Khoa_ID){
			IDbCommand cmd=this.CreateUpdateFieldCommand("TenKhoa",NewTenKhoa,Khoa_ID);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: UpdateMoTaKhoa</para>
		/// <para>Input: NewMoTaKhoa,Khoa_ID</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool UpdateMoTaKhoa(string NewMoTaKhoa,int Khoa_ID){
			IDbCommand cmd=this.CreateUpdateFieldCommand("MoTaKhoa",NewMoTaKhoa,Khoa_ID);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		#endregion

		#region Delete functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: DeleteAllCommand</para>
		/// <para>Input: </para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateDeleteAllCommand(){
			string strSQL="DELETE   FROM [Khoa]  ";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: DeleteCommand</para>
		/// <para>Input: KhoaEntity</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateDeleteCommand(KhoaEntity o){
			string strSQL="DELETE   FROM [Khoa]   WHERE [Khoa].[Khoa_ID]=@Khoa_ID";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			if(o.IsNullKhoa_ID)
				this.CreateCommandParameter(cmd,"@Khoa_ID",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@Khoa_ID",o.Khoa_ID);


			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: DeleteAll</para>
		/// <para>Input: </para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool DeleteAll(){
			IDbCommand cmd=this.CreateDeleteAllCommand();
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateDeleteByPrimaryKeyCommand</para>
		/// <para>Input: Khoa_ID</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateDeleteByPrimaryKeyCommand(int Khoa_ID){
			string strSQL="DELETE   FROM [Khoa]   WHERE [Khoa].[Khoa_ID]=@Khoa_ID";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@Khoa_ID",Khoa_ID);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: CreateDeleteByKeyCommand</para>
		/// <para>Input: ColumnName , ColumnValue</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateDeleteByKeyCommand(string ColumnName,object Value){
			string strSQL="DELETE   FROM [Khoa]   WHERE [Khoa].["+ColumnName+"]=@ColumnName";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@ColumnName",Value);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: Delete</para>
		/// <para>Input: KhoaEntity</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool Delete(KhoaEntity o){
			IDbCommand cmd=this.CreateDeleteCommand(o);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: DeleteByID</para>
		/// <para>Input: Khoa_ID</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool DeleteByID(int Khoa_ID){
			IDbCommand cmd=this.CreateDeleteByPrimaryKeyCommand(Khoa_ID);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		#endregion

		#region Select,delete by Khoa_ID functions
		#endregion

		#region MapObject functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:26/10/2011 34:05:09</para>
		/// <para>Name: MapObject</para>
		/// <para>Input: IDataReader</para>
		/// <para>Output: KhoaEntity</para>
		///</summary>
		protected override KhoaEntity MapObject(IDataReader r){
			KhoaEntity entity = new KhoaEntity();
			try{
				if(r.FieldCount>0){
					try
					{
						int ordinal = r.GetOrdinal("Khoa_ID");
						if (!r.IsDBNull(ordinal)) entity.Khoa_ID = ((int)(r.GetValue(ordinal)));
					}
					catch{}
					try
					{
						int ordinal = r.GetOrdinal("MaKhoa");
						if (!r.IsDBNull(ordinal)) entity.MaKhoa = ((string)(r.GetValue(ordinal)));
					}
					catch{}
					try
					{
						int ordinal = r.GetOrdinal("TenKhoa");
						if (!r.IsDBNull(ordinal)) entity.TenKhoa = ((string)(r.GetValue(ordinal)));
					}
					catch{}
					try
					{
						int ordinal = r.GetOrdinal("MoTaKhoa");
						if (!r.IsDBNull(ordinal)) entity.MoTaKhoa = ((string)(r.GetValue(ordinal)));
					}
					catch{}
					return entity;
				}
			}catch{}
			return null;
		}
		#endregion
	}
	/*****************************************************************************************************/
	/**********************************END KhoaDAOBase*****************************************/
	/*****************************************************************************************************/
}

